<template>
  <div class="app-container">
    <!--输入表单 -->
    <el-form label-width="120px">
      <el-form-item label="借款额度">
        <el-input-number v-model="integralGrade.borrowAmount" :min="0" />
      </el-form-item>

      <el-form-item label="积分区间开始">
        <el-input-number v-model="integralGrade.integralStart" :min="0" />
      </el-form-item>

      <el-form-item label="积分区间结束">
        <el-input-number v-model="integralGrade.integralEnd" :min="0" />
      </el-form-item>

      <el-form-item>
        <el-button :disabled="saveBtnDisabled" type="primary" @click="saveOrUpdate()">
          保存
        </el-button>
      </el-form-item>

    </el-form>
  </div>
</template>

<script>
import integralGradeApi from '@/api/core/integral-grade'
import integralGrade from '@/api/core/integral-grade'
export default {

  data () {
    return {
      saveBtnDisabled: false,
      integralGrade: {}
    }
  },

  created () {
    this.fetchById()
  },

  methods: {
    // 保存或者更新
    saveOrUpdate () {
      // 当点击保存的按钮的时候disable掉按钮，防止重复提交
      this.saveBtnDisabled = true
      if (this.integralGrade.id) {
        this.saveData()
      } else {
        this.updateData()
      }
    },

    // 调用更新

    saveData () {
      integralGradeApi.save(this.integralGrade).then(response => {
        //  this.#message({
        //    type: 'success',
        //    message: response.message
        //  })
        this.$message.success(response.message)
        this.$router.push('/core/integral-grade/list/')
      })
    },

    fetchById () {
      integralGradeApi.getById(this.$route.params.id).then(response => {
        this.integralGrade = response.data.record
      })
    },

    updateData () {
      integralGradeApi.updateById(this.integralGrade).then(response => {
        this.$message.success(response.message)
        this.$router.push('/core/integral-grade/list/')
      })
    }
  }
}
</script>